import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-11-28
 * Time: 22:25
 */
public class boolsort {
    public static void sort(int[] arr) {
        boolean swapped;
        for (int i = 0; i < arr.length - 1; i++) {
            swapped = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > (arr[j + 1])) {
                    // 交换
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                    swapped = true;
                }
            }
            System.out.println("第" + (i + 1) + "遍：" + Arrays.toString(arr));
            // 如果这一轮没有发生交换，说明数组已经有序，可以提前结束
            if (!swapped) {
                break;
            }
        }
    }
    public static void main(String[] args) {
        int[] arr = new int[]{56, 1, 88, 66, 35, 7, 6, 2};
        sort(arr);
    }

}
